﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using System.Globalization;
using Chefbook.ViewModels;

namespace Chefbook.UserActions
{
    /// <summary>
    /// An action to rename a category
    /// </summary>
    public class RenameCategoryAction : UserActionBase
    {
        private string oldName, newName;
        private CategoryViewModel categoryToRename;

        /// <summary>
        /// Creates a new action to rename a category
        /// </summary>
        /// <param name="categoryToRename">The category to rename</param>
        /// <param name="newName">The new name</param>
        public RenameCategoryAction(CategoryViewModel categoryToRename, string newName):base()
        {
            this.categoryToRename = categoryToRename;
            this.oldName = categoryToRename.Name;
            this.newName = newName;
        }

        /// <summary>
        /// Renames the category
        /// </summary>
        public override void DoAction()
        {
            base.DoAction();
            categoryToRename.Name = newName;
        }

        /// <summary>
        /// Reverts the category to its previous name
        /// </summary>
        public override void UndoAction()
        {
            base.UndoAction();
            categoryToRename.Name = oldName;
        }

        /// <summary>
        /// Returns a user-friendly string describing the action
        /// </summary>
        /// <returns>A user-friendly string describing the action</returns>
        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "Rename Category from '{0}' to '{1}'", oldName, newName);
        }
    }
}
